# custom_db_backend.py

from django.db.backends.mysql.base import DatabaseWrapper as MySQLDatabaseWrapper
from seckill_java_topy.custom_db_backend.db_pool import get_connection  # 引入连接池

class DatabaseWrapper(MySQLDatabaseWrapper):
    def get_new_connection(self, conn_params):
        # 从连接池中获取连接
        return get_connection()

    def _close(self, connection):
        # 不直接关闭连接，而是将其返回到连接池
        pass

    def _set_autocommit(self, autocommit):
        # 确保 autocommit 方法作用于底层的原生连接
        if hasattr(self.connection, '_con'):
            self.connection._con.autocommit(autocommit)
        else:
            super()._set_autocommit(autocommit)